#ifndef Node2D_H
#include "AffineTransform.h"
#include "HelloOpenGLCommon.h"
#include "Texture.h"
#include "Technique.h"
#include <vector>
#define Node2D_H
class Node2D
{
public:
	Node2D(void);
	~Node2D(void);
	void update(unsigned int stageWidth,unsigned int stageHeight);
	void draw(Technique* pEffect);
	void setTexture(Texture* texture);
	void setName(std::string name);
	std::string getName();
	void addChild(Node2D* child);
	void addChild(Node2D* child,int index);
	Node2D* getChildAt(int index);
	//return -1 if find nothing
	int getChildIndex(Node2D* child);
	void removeChild(Node2D* child);
	void removeChildAt(int index);
	void removeAllChildren();
	void setChildIndex(Node2D* child,int index);
	void swapChildren(Node2D* child1,Node2D* child2);
	void swapChildrenAt(int index1,int index2);
	int count();
	void setParent(Node2D* parent);
	Node2D* getParent();
	bool isIncludeChild(Node2D* child);
    CCAffineTransform nodeToParentTransform(void);
    CCAffineTransform parentToNodeTransform(void);
    CCAffineTransform nodeToWorldTransform(void);
	CCAffineTransform worldToNodeTransform(void);
	CCPoint convertToNodeSpace(const CCPoint& worldPoint);
    CCPoint convertToWorldSpace(const CCPoint& nodePoint);
	float nodeToWorldAlpha();
private:
	void doTransfrom(Vertex3F& vertices,CCAffineTransform transform);
public:
	CCPoint mPos;
	CCPoint mAnchorPointInPoints;    ///< anchor point in points
	CCPoint mAnchorPoint;            ///< anchor point normalized (NOT in points) 
	CCSize mContentSize;             ///< untransformed size of the node
	float mRotation;
	float mScaleX;
	float mScaleY;
	float mSkewX;
	float mSkewY;
	float mAlpha;

	std::vector<Node2D*> mChildren;
	Node2D* mParent;

	// vertex coords, texture coords and color info
	V3F_C4B_T2F_Quad mQuad;
	Texture* pTexture;

	char* mName;
};
#endif

